<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/

  class bm_whats_new {
    var $code = 'bm_whats_new';
    var $group = 'boxes';
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;

    function bm_whats_new() {
      $this->title = MODULE_BOXES_WHATS_NEW_TITLE;
      $this->description = MODULE_BOXES_WHATS_NEW_DESCRIPTION;

      if ( defined('MODULE_BOXES_WHATS_NEW_STATUS') ) {
        $this->sort_order = MODULE_BOXES_WHATS_NEW_SORT_ORDER;
        $this->enabled = (MODULE_BOXES_WHATS_NEW_STATUS == 'True');

        $this->group = ((MODULE_BOXES_WHATS_NEW_CONTENT_PLACEMENT == 'Left Column') ? 'boxes_column_left' : 'boxes_column_right');
      }
    }

    function execute() {
      global $currencies, $oscTemplate;

      /*if ($random_product = tep_random_select("select products_id, products_image, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status = '1' order by products_date_added desc limit " . MAX_RANDOM_SELECT_NEW)) {
        $random_product['products_name'] = tep_get_products_name($random_product['products_id']);
        $random_product['specials_new_products_price'] = tep_get_products_special_price($random_product['products_id']);

        if (tep_not_null($random_product['specials_new_products_price'])) {
          $whats_new_price = '<del>' . $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</del><br />';
          $whats_new_price .= '<span class="productSpecialPrice">' . $currencies->display_price($random_product['specials_new_products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</span>';
        } else {
          $whats_new_price = $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id']));
        }

        $data = '<div class="ui-widget infoBoxContainer">' .
                '  <div class="ui-widget-header infoBoxHeading"><a href="' . tep_href_link(FILENAME_PRODUCTS_NEW) . '">' . MODULE_BOXES_WHATS_NEW_BOX_TITLE . '</a></div>' .
                '  <div class="ui-widget-content infoBoxContents" style="text-align: center;"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $random_product['products_image'], $random_product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br /><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . $random_product['products_name'] . '</a><br />' . $whats_new_price . '</div>' .
                '</div>';

        $oscTemplate->addBlock($data, $this->group);
      }*/
	  $whats_new_query = tep_db_query("select products_id, products_image, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status = '1' order by products_date_added desc limit 10");
	  if (tep_db_num_rows($whats_new_query) >= 5) {
		
		
		
		
		$data = '<div class="blk_sty">'.
                  '<h1 class="title_blk_sty"><a href="' . tep_href_link(FILENAME_PRODUCTS_NEW) . '">' . MODULE_BOXES_WHATS_NEW_BOX_TITLE . '</a><!-- <span class="taileft"> </span> <span class="tairight"> </span>--></h1>' ;
						'<div class="main_blk_sty">'.
						'<div id="menu-vertical">'.						
		//$info_box_contents = array();
		//$info_box_contents[] = array('text' => BOX_HEADING_WHATS_NEW);
		//new infoBoxHeading($info_box_contents, false, false, tep_href_link(FILENAME_PRODUCTS_NEW));
		
		
		$rows = 0;
		$bestsellers_list = '<table border="0" width="100%" cellspacing="0" cellpadding="0">';		
		while ($whats_new = tep_db_fetch_array($whats_new_query)) {
		$rows++;
		
		$whats_new['products_name'] = tep_get_products_name($whats_new['products_id']);
        $whats_new['specials_new_products_price'] = tep_get_products_special_price($whats_new['products_id']);

        if (tep_not_null($whats_new['specials_new_products_price'])) {
          $whats_new_price = '<del>' . $currencies->display_price($whats_new['products_price'], tep_get_tax_rate($whats_new['products_tax_class_id'])) . '</del><br />';
          $whats_new_price .= '<span class="productSpecialPrice">' . $currencies->display_price($whats_new['specials_new_products_price'], tep_get_tax_rate($whats_new['products_tax_class_id'])) . '</span>';
        } else {
          $whats_new_price = $currencies->display_price($whats_new['products_price'], tep_get_tax_rate($whats_new['products_tax_class_id']));
        }
		  
		//$bestsellers_list .= '<tr><td class="infoBoxContents" valign="top"></td>';  
		$bestsellers_list .= '<td class="infoBoxContents" align="center">';
		//$bestsellers_list .= '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $whats_new['products_id']) . '">' . $whats_new['products_name'] . '</a><br>';
		$bestsellers_list .= '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $whats_new['products_id']) . '">';
		$bestsellers_list .= tep_image(DIR_WS_IMAGES . $whats_new['products_image'], $whats_new['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
		$bestsellers_list .= '<br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $whats_new['products_id']) . '">' . $whats_new['products_name'] . '</a><br /><span style="color:black;">'. $whats_new_price . '</span><br/>';
		$bestsellers_list .= '</td></tr>';
		}
		$bestsellers_list .= '</table>';
		
		$data .= '<div class="ScrollItem" align="left"><MARQUEE behavior= "scroll" align= "left" direction= "up" height="200" width="235" scrollamount= "2" scrolldelay= "50" onmouseover=\'this.stop()\' onmouseout=\'this.start()\'><div>'.$bestsellers_list.'</div></MARQUEE></div>';
		//BOF code added all products SEO contribs
		//$info_box_contents[] = array('align' => 'center',
        //                       'text' => '<a class="allproductsBox" href="' . tep_href_link(FILENAME_PRODUCTS_NEW) . '" title="' . BOX_INFORMATION_ALLPRODS_SEO_WHATSNEW . '">' . BOX_INFORMATION_ALLPRODS_SEO_WHATSNEW .'</a>');
		//EOF code added all products SEO contribs

		//new infoBox($info_box_contents);
		
		$data .='</div>';
		$oscTemplate->addBlock($data, $this->group);
	  }
    }

    function isEnabled() {
      return $this->enabled;
    }

    function check() {
      return defined('MODULE_BOXES_WHATS_NEW_STATUS');
    }

    function install() {
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable What\'s New Module', 'MODULE_BOXES_WHATS_NEW_STATUS', 'True', 'Do you want to add the module to your shop?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Content Placement', 'MODULE_BOXES_WHATS_NEW_CONTENT_PLACEMENT', 'Left Column', 'Should the module be loaded in the left or right column?', '6', '1', 'tep_cfg_select_option(array(\'Left Column\', \'Right Column\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_BOXES_WHATS_NEW_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
    }

    function remove() {
      tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_BOXES_WHATS_NEW_STATUS', 'MODULE_BOXES_WHATS_NEW_CONTENT_PLACEMENT', 'MODULE_BOXES_WHATS_NEW_SORT_ORDER');
    }
  }
?>
